package com.mill.scala.aop

import org.aspectj.lang.ProceedingJoinPoint
import org.aspectj.lang.annotation.{Around, Aspect}
import org.springframework.stereotype.Component
import org.springframework.web.servlet.ModelAndView

case class ResultObj(code:Int,msg:String,obj:AnyRef)

/**
  * 用一个返回结果包封装
  */
@Aspect
@Component
class ResultAop {


  @Around("@annotation(org.springframework.web.bind.annotation.RequestMapping)")
  def handResult(pjp:ProceedingJoinPoint): AnyRef ={
    try{
      val r=pjp.proceed(pjp.getArgs)
      println("=====================================================")
      println(r.getClass)
//      if(r.isInstanceOf[ModelAndView]){
//        val s = r.asInstanceOf[ModelAndView]
//      }
      return ResultObj(200,"successful",r)
    }catch {
      case ex:Exception=>{
        println("error")
      }
    }
    ResultObj(400,"is error",None)
  }
}
